package com.slt.concurrency;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        int arr[] = new int[]{1, 2, 2, 3};
        List list = selectOne2(arr);
        System.out.println(list);
    }
    public static List selectOne(int [] arr){
        Map<Integer,Integer> map = new HashMap();
        List list = new ArrayList();
        for (int i = 0; i < arr.length; i++) {
            if(!map.keySet().contains(arr[i])){
                map.put(arr[i],1);
            }else {
                map.put(arr[i],map.get(arr[i])+1);
            }
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if(entry.getValue() == 1){
                list.add(entry.getKey());
            }
        }
        return list;
    }
    public static List selectOne2(int [] arr){
        Map<Integer,Integer> map = new HashMap();
        List<Integer> list = new ArrayList();
        Set<Integer> set = new HashSet<>();
        for (int item : arr) {
            if(!list.contains(item)){
                list.add(item);
            }else {
                set.add(item);
            }
        }
        list.removeAll(set);
        return list;
    }

}
